home *** CD-ROM | disk | FTP | other *** search
- /* ShowNI 40.1 - By Eric Sauvageau */
-
- /* This will take a list of icons, and display them in a window as
- buttons. ClassAct is required.
-
- If the SELECT option is enabled, then clicking on an icon will output
- the file's name (as passed on the commandline, so it might or might not
- have the ".info" suffix. This is not a problem for CopyNewIcon, but
- you must be aware of this if you intend to use ShowNI for other
- applications). ShowNI will exist immediately in that case.
-
- Handy for icon selection in Installer scripts.
-
-
- Usage:
-
- SELECT\S = Boolean. If present, ShowNI exits at the first selected
- icon, returning the filename.
-
- TITLE\K = Optional string for the window's titlebar. Default is
- "ShowNI".
-
- LABEL\K = Optional string for the label shown while in Select mode.
- Default is "Select an icon:".
-
- ICONS\M\A = A list of icons to show in the window. A maximum of
- 15 icons are supported.
-
- */
-
- /*** Uncomment to enable debug output to stdout ***/
-
- /* #define DEBUG */
-
-
-
- /*** Maximum icons supported ***/
-
- #define MAXICONS 15
-
-
- #include <clib/macros.h>
- #include <clib/alib_protos.h>
- #include <libraries/gadtools.h>
- #include <intuition/icclass.h>
- #include <intuition/intuition.h>
-
- #include <proto/exec.h>
- #include <proto/dos.h>
- #include <proto/utility.h>
- #include <proto/graphics.h>
- #include <proto/intuition.h>
- #include <proto/asl.h>
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
-
- #include <classact.h>
- #include <classact_author.h>
-
- #include <proto/button.h>
- #include <proto/window.h>
- #include <proto/layout.h>
- #include <proto/label.h>
- #include <proto/newicon.h>
-
- #include <gadgets/button.h>
- #include <classes/window.h>
-
- #include <gadgets/layout.h>
- #include <images/label.h>
-
- #include <libraries/newicon.h>
-
-
-
-
- /*** GadgetIDs ***/
- enum
- {
- ID_LAYOUT=1,
- ID_BUTROW,
- ID_WINDOW,
- ID_LABEL,
- ID_BUT1,
-
- ID_LAST
- };
-
-
- enum
- {
- ARG_LABEL=0,
- ARG_TITLE,
- ARG_SEL,
- ARG_ICONS,
- ARG_LAST
- };
-
-
-
- /* Being global, the elements are initialized to 0. */
-
- long ARG[ARG_LAST];
- struct Image *imagenorm[MAXICONS];
- struct Image *imagesel[MAXICONS];
- struct NewDiskObject *diskobjects[MAXICONS];
-
-
- struct NewIconBase *NewIconBase;
-
-
- struct NewDiskObject *MyGetNewDiskObject(UBYTE *name);
- VOID mystrcpy(UBYTE *to,UBYTE *from);
-
-
- int main()
- {
- struct RDArgs *args;
- BOOL selectmode;
- char **filenames;
- BOOL HasValidIcons=FALSE;
-
- int count;
-
- struct Window *window;
- Object *Objects[ID_LAST];
-
- struct Screen *scr;
-
-
- if (!(args = ReadArgs("LABEL/K,TITLE/K,S=SELECT/S,ICONS/M/A", ARG, NULL)))
- {
- PrintFault(IoErr(), NULL); /* prints the appropriate error message */
- return RETURN_ERROR;
- }
-
- if (scr = LockPubScreen(NULL))
- {
-
- NewIconBase = (struct NewIconBase *) OpenLibrary("newicon.library",39L);
-
- if (WindowBase && LayoutBase && ButtonBase && NewIconBase && LabelBase)
- {
-
- /*** Process passed arguments, opening icons and remapping them ***/
-
- selectmode = ARG[ARG_SEL];
- #ifdef DEBUG
- if (selectmode) printf("Select mode\n");
- #endif
-
- count = 0;
- filenames = (char **) ARG[ARG_ICONS];
-
- while ((*filenames) && (count < MAXICONS))
- {
-
- /*** Using Nicola's version - it removes any trailing .info ***/
-
- if (diskobjects[count] = MyGetNewDiskObject(*filenames))
- {
-
- /* If we can get (at least one ) valid image, set HasValidIcons to TRUE. */
-
- if (imagenorm[count] = RemapChunkyImage(diskobjects[count]->ndo_NormalImage,scr)) (HasValidIcons = TRUE);
- imagesel[count] = RemapChunkyImage(diskobjects[count]->ndo_SelectedImage,scr);
- }
- #ifdef DEBUG
- printf("count =%d imagenorm = %ld imagesel = %ld dobj = %ld\n",count, imagenorm[count], imagesel[count], diskobjects[count]);
- printf("name = %s\n",(*filenames));
- #endif
- count++;
- filenames++;
- };
-
- /* Check if we have at least one valid NewIcon image to display */
-
- if (HasValidIcons)
- {
-
- Objects[ID_WINDOW] = WindowObject,
- WA_Title, ((ARG[ARG_TITLE]) ? (char *)ARG[ARG_TITLE] : "ShowNI"),
- WA_DepthGadget, TRUE,
- WA_DragBar, TRUE,
- WA_CloseGadget, TRUE,
- WA_Activate,TRUE,
- WINDOW_Position, WPOS_CENTERSCREEN,
- WINDOW_ParentGroup, Objects[ID_LAYOUT] = VLayoutObject,
- LAYOUT_SpaceOuter, TRUE,
- LAYOUT_DeferLayout, TRUE,
-
- LAYOUT_AddChild, Objects[ID_BUTROW] = HLayoutObject, HCentered,
-
- /*** Empty group - we'll add stuff later. ***/
-
- EndGroup,
-
- EndMember,
- EndWindow;
-
- if (Objects[ID_WINDOW])
- {
-
- /* If select mode, then display the header label */
- if (selectmode)
- {
- SetAttrs(Objects[ID_LAYOUT],
- LAYOUT_AddImage, Objects[ID_LABEL] = LabelObject,
- IA_Font, scr->Font,
- LABEL_Text, ( ARG[ARG_LABEL] ? (char *)ARG[ARG_LABEL] : "Select an icon:"),
- EndImage,
- TAG_DONE);
- }
-
- count = 0;
- filenames = (char **) ARG[ARG_ICONS];
-
- while ((*filenames) && (count < MAXICONS))
- {
-
- /*** Only add it if we do have an icon ***/
-
- if (imagenorm[count])
-
- SetAttrs(Objects[ID_BUTROW],
- LAYOUT_AddChild, ButtonObject,
- GA_ID, (ID_BUT1+count),
- GA_RelVerify, TRUE,
- GA_Image, imagenorm[count],
- GA_SelectRender, imagesel[count],
- ButtonEnd,
- CHILD_WeightedWidth,0,
- CHILD_WeightedHeight,0,
- TAG_DONE);
-
- count++;
- filenames++;
-
- }
-
-
- if (window = (struct Window *) CA_OpenWindow(Objects[ID_WINDOW]))
-
- /*** We'll need it again below ***/
-
- filenames = (char **) ARG[ARG_ICONS];
-
- {
- ULONG wait, signal, result, done = FALSE;
- WORD code;
-
- GetAttr(WINDOW_SigMask, Objects[ID_WINDOW], &signal);
-
- while (!done)
- {
- wait = Wait(signal|SIGBREAKF_CTRL_C);
-
- if (wait & SIGBREAKF_CTRL_C) done = TRUE;
- else
-
- while ((result = CA_HandleInput(Objects[ID_WINDOW], &code)) != WMHI_LASTMSG)
- {
- switch (result & WMHI_CLASSMASK)
- {
- case WMHI_CLOSEWINDOW:
- done = TRUE;
- break;
-
- case WMHI_GADGETUP:
- if (selectmode)
- {
- printf("%s\n", filenames[ (LONG) (result & WMHI_GADGETMASK) - ID_BUT1]);
- done = TRUE;
- }
- break;
-
- }
- }
- }
- }
-
- DisposeObject(Objects[ID_WINDOW]);
- }
- }
- else
- {
- printf("No valid NewIcon specified.\n");
- }
- }
-
-
- /*** Freeing our images and icons ***/
-
- count=0;
-
- /***
- Filename ptr was restored just after opening our GUI, so
- no need to restore it again.
- ***/
-
- while ((*filenames) && (count < MAXICONS))
- {
- #ifdef DEBUG
- printf("count =%d imagenorm = %ld imaegsel = %ld dobj = %ld\n",count, imagenorm[count], imagesel[count], diskobjects[count]);
- #endif
- if (imagenorm[count]) FreeRemappedImage(imagenorm[count],scr);
- if (imagesel[count]) FreeRemappedImage(imagesel[count],scr);
- if (diskobjects[count]) FreeNewDiskObject(diskobjects[count]);
- count++;
- filenames++;
- }
-
- if (scr) UnlockPubScreen(NULL,scr);
-
- }
-
- /*** We're closing down. ***/
-
- if (NewIconBase) CloseLibrary((struct Library *) NewIconBase);
-
- FreeArgs(args);
-
- }
-
-
-
- /*** read an icon stripping trailing .info from name ***/
-
- struct NewDiskObject *MyGetNewDiskObject(UBYTE *name)
- {
- UBYTE buf[128];
-
-
- mystrcpy(buf,name);
- return(GetNewDiskObject(buf));
- }
-
-
- VOID mystrcpy(UBYTE *to,UBYTE *from)
- {
- LONG len;
-
-
- strcpy(to,from);
- len = strlen(to);
- if (len > 5 && !stricmp(&to[len-5],".info"))
- to[len-5] = 0;
- }
-
-
- UBYTE versionstring20[] = "\0$VER: ShowNI 40.1 (8.7.97)";
-